<template>
    <div>
            <el-button type="primary" @click="dialogFormVisible=true;formData={}; title='添加'">添加</el-button>
        <el-table :data="list" border style="width: 100%" height="500px">
            <el-table-column fixed prop="" label="序号" width="50">
                <template slot-scope="scope">
                    {{ scope.$index + 1 }}
                </template>
            </el-table-column>
            <el-table-column fixed prop="regionid" label="地区编号" width="100"/>
            <el-table-column fixed prop="regionname" label="地区名称"/>
            <el-table-column fixed prop="remark" label="备注"/>
        </el-table>

        <el-dialog :title="title" :visible="dialogFormVisible">
            <el-form :model="formData">
                <el-form-item label="地区编号" :label-width="formLabelWidth">
                    <el-input v-model="formData.regionid"/>
                </el-form-item>
                <el-form-item label="地区名称" :label-width="formLabelWidth">
                    <el-input v-model="formData.regionname" ></el-input>
                </el-form-item>
                <el-form-item label="备注" :label-width="formLabelWidth">
                    <el-input v-model="formData.remark" ></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible=false">取消</el-button>
                <el-button type="primary" @click="submits('formData')">确定</el-button>
            </div>
        </el-dialog>
    </div>

</template>

<script>
export default {
    name: "Region",
    data() {
        return {
            list:[],
            title:'添加地区',
            dialogFormVisible:false,
            formLabelWidth:'120px',
            formData:{}
        }
    },
    created () {
        this.getList();
    },
    methods: {
        getList() {
            this.$http.post('/region/select').then(res => {
                console.log(11111)
                console.log(res);
                this.$data.list = res;
            })
        },
        submits(form){
            this.$http.post("/region/addRegion",this.$data.formData).then(res=>{
                console.log(res)
                if (res){
                    this.$message.success("成功");
                    this.getList();
                    this.dialogFormVisible=false;
                }else{
                    this.$message.error("失败");
                    this.dialogFormVisible=false;
                }
            })
        }
    }

    }

</script>

<style scoped>

</style>
